﻿<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>

<input type="text" id ="text" />
<span style="position:absolute;">
    <div id="div1" style="width:200px;height:160px;border:solid 1px 
red;">鼠标跟随</div>
</span>
<script> 
var  t = document.getElementById("text");
var div1 = document.getElementById("div1");
div1.onmousemove = function(event){
    var event = event || window.event; 		// 标准化事件对象
    if(event.offsetX || event.offsetY ){
        t.value = event.offsetX + " " + event.offsetY;
    }
    else if(event.layerX || event.layerY ){
        t.value = (event.layerX - 1) + " " + (event.layerY -1) ;
    }
}
</script>

</body>
</html>
